<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\UserNumHistory;
use App\Models\User;

class UserNumHistoriesController extends Controller
{

    public function edit(Request $request)
    {
        //获取历史充值记录
        $user_num_histories = UserNumHistory::with('operator')->where('user_id', \Auth::id())->where('is_deleted', 0)->orderBy('updated_at', 'desc')->paginate(10);

        if ($request->ajax()) {
            $view = view('mobile.layouts._recharge-history-item',compact('user_num_histories'))->render();
            return response()->json(['html'=>$view]);
        }

        return view(isMobile() . 'mobile_recharge.edit', compact('user_num_histories'));
    }


    public function historyDelete(User $user, Request $request)
    {
        if($request->ajax()) {

            $user_num_history = UserNumHistory::where('user_id', \Auth::id())->first();

            $this->authorize('destroy', $user_num_history);

            $user_num_history = UserNumHistory::where('id', $request->delete_id)->first();

            $user_num_history->update([
                'is_deleted' => 1,
            ]);
        }
    }
}
